import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:enterprise_v8/app/core/utils/user_manager.dart';
import 'package:enterprise_v8/app/data/entities/application/securtity_base_drawer.dart';
import 'package:enterprise_v8/generated/assets.gen.dart';

class WorkbenchControl extends GetxController {
  /// 选中的页面
  int selectIndex = 0;

  // 标题列表
  final titleList = <SecurityBaseEntity>[];

  @override
  void onReady() {
    super.onReady();
    // 如果没有登录,则不执行逻辑,防止请求401
    if (!UserManager.isLoggedIn) {
      return;
    }
    _initTitleList();
  }

  Future<void> _initTitleList() async {
    titleList.clear();
    titleList.addAll([
      SecurityBaseEntity(
        title: '封闭化',
        icon: Assets.svg.iconJobRight.path,
        expandTitle: '封闭化',
        pages: [Container()],
        path: '/closure',
      ),
      SecurityBaseEntity(
        title: '安全基础',
        icon: Assets.svg.iconJobRight.path,
        expandTitle: '安全基础',
        pages: [Container()],
        path: '/basicInformation',
      ),
      SecurityBaseEntity(
        title: '风险管控',
        icon: Assets.svg.iconJobRight.path,
        expandTitle: '风险管控',
        pages: [Container()],
        path: '/riskControl',
      ),
      SecurityBaseEntity(
        title: '智能巡检',
        icon: Assets.svg.iconJobRight.path,
        expandTitle: '智能巡检',
        pages: [Container()],
        path: '/intelligentInspection',
      ),
      SecurityBaseEntity(
        title: '敏捷应急',
        icon: Assets.svg.iconJobRight.path,
        expandTitle: '敏捷应急',
        pages: [Container()],
        path: '/emergency',
      ),
    ]);
    // await ModulePermissionsUtil.removeTaskRoleMenu(titleList: titleList);
    update();
  }

  /// 点击左侧菜单
  /// [index] 索引
  void selectLeftMenu(int index) {
    selectIndex = index;
    update();
  }

  /// title选择切换
  /// [titleIndex] 标题索引
  /// [index] 页面索引
  void selectTitle(int titleIndex, int index) {
    titleList[titleIndex].currentPageTitle = index;
    update();
  }

  /// 点击展开菜单
  /// [index] 索引
  void selectExpandMenu(int index) {
    selectIndex = index;
    Get.back();
    update();
  }
}
